package com.bida.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.bida.core.auth.ClientAuthService;
import com.bida.core.constant.UrlConstant;

/**
 * 
 * @author chenli
 *
 */
@RestController
@RequestMapping("rest/token_manager")
public class TokenManagerController {

    @RequestMapping(value = "/{clientId}/{appSecret}/{state}", method = RequestMethod.GET)
    @ResponseBody
    public String getClientAuthUrl(@PathVariable("clientId") String clientId, @PathVariable("appSecret") String appSecret,
	    @PathVariable("state") String state,HttpServletRequest request,HttpServletResponse response ) {
	
	//测试获取客户端授权的临时令牌code
        Map<String, String> params2 = new HashMap<String, String>();
        params2.put("site", UrlConstant.ALI_PRESS_SITE_EN);
        params2.put("client_id", clientId);
        params2.put("redirect_uri", UrlConstant.ALI_APP_URL);
        params2.put("state", state);
        String clientAuthUrl = ClientAuthService.getClientAuthUrl(UrlConstant.ALI_PRESS_HOST_EN, params2, appSecret);
        return clientAuthUrl;
    }
}
